import {Injectable} from '@angular/core';
import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http';
import {serialize} from '@angular/compiler/src/i18n/serializers/xml_helper';
import {Observable} from 'rxjs/Observable';

const httpOptions = {
  headers: new HttpHeaders({
    'Content-Type': 'application/json;text/html'
  })
};

const url: string = '/api/user';

@Injectable()
export class UserService {
  message: string;

  constructor(private httpClient: HttpClient) {

  }

  registerUser(user: User): Observable<Result> {
    return this.httpClient.post<Result>(url + '/saveUser/121', user, httpOptions);
  }

  login(user: User): Observable<Result> {
    return this.httpClient.post<Result>(url + '/login', user);
  }

}

enum result {FALIURE, SUCCESS}

export class User {

  constructor(
    public username?: string,
    public password?: string,
    public phoneNumber?: number,
    public address?: string
  ) {
  }
}

export class Product {
  constructor(
    public id?: number,
    public title?: string,
    public price?: number,
    public rating?: number,
    public desc?: string,
    public categories?: Array<string>
  ) {
  }
}
